package com.yf.springboot.bean;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;

@PropertySource(value = {"classpath:car.properties"}) //支持properties,不支持yml。测试car.yml失败，无法通过配置文件给对象赋值
//@ConfigurationProperties(prefix = "car")
public class Car {
    // 方式三：从配置文件中读取
    @Value("${car.band}")
    private String band;

    // 方式四：spEL表达式
    @Value("#{11*2}")
    private String cc;

    public Car() {
    }

    public Car(String band, String cc) {
        this.band = band;
        this.cc = cc;
    }

    public String getBand() {
        return band;
    }

    public void setBand(String band) {
        this.band = band;
    }

    public String getCc() {
        return cc;
    }

    public void setCc(String cc) {
        this.cc = cc;
    }

    @Override
    public String toString() {
        return "Car{" +
                "band='" + band + '\'' +
                ", cc='" + cc + '\'' +
                '}';
    }
}
